#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author   : PR
# @Time     : 2023/1/10 9:15
# @File     : readExcel.py
# @Project  : pythonoffice
import os
import time

import pandas as pd
import  io

from pandas import DataFrame


# def readExcelPd(excelPath):
# # 第二步：读入文件
#     df = pd.read_excel(io=excelPath)
#     return  df;

def readExcel(excelPath):
    df: DataFrame = pd.read_excel(io=excelPath)
    return df
def readExcelWithSheetName(excelPath,sheetName):
    df: DataFrame = pd.read_excel(io=excelPath,sheet_name=sheetName)
    return df

def exportExcel(open_path,df,exportName):
    filename = os.path.basename(open_path)
    # print(os.path.basename(path))

    stem, suffix = os.path.splitext(filename)
    # print(stem)  # test
    # print(suffix)  # .py
    exportPath = os.path.split(os.path.abspath(open_path))[0]
    filename = os.path.split(os.path.abspath(open_path))[1]
    now_time = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())
    # outname = "./"+stem+"更新excel列" + now_time + ".xlsx"
    outname = "./"+stem+exportName + now_time + ".xlsx"
    # print(outname)
    outputPath = exportPath +outname
    # outputPath = exportPath +'./excel转txt1.txt'
    # df.to_excel(outputPath, sep='\t', index=None)
    # df.to_excel(outputPath,index = False,encoding="utf-8")
    df.to_excel(outputPath,index = False)
    print('导出excel完成'+outputPath)

def save_json(open_path,df,exportName):
    # json_list = json_inputs(open_path)
    # df = pd.read_excel(open_path)
    filename = os.path.basename(open_path)
    # print(os.path.basename(path))

    stem, suffix = os.path.splitext(filename)
    # print(stem)  # test
    # print(suffix)  # .py
    exportPath = os.path.split(os.path.abspath(open_path))[0]
    now_time = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())
    outname = "./"+stem+exportName + now_time + ".txt"
    # print(outname)
    outputPath = exportPath +outname
    # outputPath = exportPath +'./excel转txt1.txt'
    df.to_csv(outputPath, sep='\t', index=None)